/**
 * Created with IntelliJ IDEA
 * Description: 有三个线程，线程名称分别为：a，b，c。
 *              每个线程打印自己的名称。
 *              需要让他们同时启动，并按 c，b，a的顺序打印
 * User：chenshu
 * Date：2023-11-08
 * Time：13:25
 */
public class Work1 {
    static Object locker1 = new Object();
    static Object locker2 = new Object();

    public static void main(String[] args) {
        Thread ta = new Thread(() -> {
            synchronized (locker1) {
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("a");
            }
        });

        Thread tb = new Thread(() -> {
            synchronized (locker2) {
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("b");
                synchronized (locker1) {
                    locker1.notify();
                }
            }
        });

        Thread tc = new Thread(() -> {
            synchronized (locker2) {
                System.out.println("c");
                locker2.notify();
            }
        });

        ta.start();
        tb.start();
        tc.start();
    }
}
